package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.domain.StrategyDetail;
import cn.wolfcode.trip.base.query.StrategyQuery;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyDetailService;
import cn.wolfcode.trip.base.service.IStrategyService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 攻略资源控制器
 */
@RestController
@RequestMapping("strategies")
public class StrategyController {

    @Autowired
    IStrategyService strategyService;

    @Autowired
    IStrategyCatalogService catalogService;

    @Autowired
    IStrategyDetailService detailService;

    @GetMapping
    public PageInfo query(StrategyQuery qo){
        return strategyService.query(qo);
    }

    /**
     *
     * 根据id获取大攻略对象
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Strategy getById(@PathVariable Long id){
        Strategy strategy=strategyService.getById(id);
        return strategy;
    }

    /**
     * 根据大攻略的id查询攻略分类集合
     * @param id
     * @return
     */
    @GetMapping("/{id}/catalogs")
    public List<StrategyCatalog> listCatalogByStrategyId(@PathVariable Long id){
        List<StrategyCatalog> strategyCatalogs = catalogService.listByStrategyId(id);
        return strategyCatalogs;
    }

    /**
     * 根据攻略文章的id查询文章数据
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    public StrategyDetail getDetailsById(@PathVariable Long id){
        return detailService.getDetailsById(id);
    }
}
